import { ref } from 'vue'
import {getSmsTemplateDetail, updateSmsTemplateState} from '../../../../api/sms'
import { SmsTemplateDetail } from '../types'

// 获取短信模版详情加载状态
const getSmsTemplateDetailLoading = ref(false)

// 短信模版详情
const smsTemplateDetail = ref<SmsTemplateDetail | null>(null)

// 获取短信模版详情方法
const getSmsTemplateDetailFn = async (id: string | number) => {
    getSmsTemplateDetailLoading.value = true
    const res = await getSmsTemplateDetail(id)
    smsTemplateDetail.value = res.data.data.row
    getSmsTemplateDetailLoading.value = false
}

// 更新模版状态加载
const updateSmsTemplateLoading = ref(false)

// 更新模版详情方法
const updateSmsTemplateFn = async (ids: Array<string | number>, status: boolean) => {
    updateSmsTemplateLoading.value = true
    const res = await updateSmsTemplateState({ids, status})
    updateSmsTemplateLoading.value = false
    return res.data
}

export default {
    smsTemplateDetail,
    updateSmsTemplateLoading,
    getSmsTemplateDetailLoading,
    updateSmsTemplateFn,
    getSmsTemplateDetailFn,
}
